package com.cg.ai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;
import java.time.Duration;

/**
 * 公共配置类
 */
@Configuration
public class CommonConfiguration {

    /**
     * 配置聊天客户端
     */
    @Bean
    public ChatClient chatClient(ChatModel model) {
        return ChatClient
                .builder(model)
                .defaultSystem("你是一个乐于助人的中文助手，请简洁准确地回答问题。")
                .build();
    }

    /**
     * 配置REST模板
     */
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder
                .setConnectTimeout(Duration.ofSeconds(20))
                .setReadTimeout(Duration.ofSeconds(120))
                .build();
    }
}